package com.game.server.system;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.game.majiang.config.LogManager;

import com.game.majiang.logic.LogicTable;
import lombok.ToString;
import lombok.extern.log4j.Log4j;

@ToString
public abstract class AbstractRoom extends AbstractPlayerBase {
	
    protected Map<Integer, AbstractTable> tables;

    
    public int type;
    
    public int gettype()
    {
    	return type;
    }
    
    public void settype(int type)
    {
    	this.type = type;
    }

    public AbstractRoom(int id) {
        super(id);
        tables = new HashMap<Integer, AbstractTable>();
        		
    }

    public AbstractTable getTables(int tableId) {
        return tables.get(tableId);
    }
    
    public int getTablesCount() {
        return tables.size();
    }
    
   
    /**
     *增加桌子
     * 
     * @param table
     */
    public boolean addTable(AbstractTable table) {
        synchronized (tables) {
            if (!tables.containsKey(table.getID())) {
               tables.put(table.getID(), table);
               table.settype(gettype());
               return true;
            }
        }
        return false;
    }
    
    /**
     * 移除桌子
     * @param table
     */
    public void removeTable(AbstractTable table) {
        System.out.println("移除桌子:"+table);
        synchronized (tables) {
            if (tables.remove(table.getID()) != null)
            {
            	LogManager.getInstance().Log("ID:" + table.getID() + "关闭！");
            }
        }
    }

    /**
     * 桌子列表
     * @return
     */
    public ArrayList<AbstractTable> getTables() {
        synchronized (tables) {
           return new ArrayList<>(tables.values());
        }
    }
    

	/**
	 * 获得桌子
	 * @param id
	 */
	public AbstractTable getTable(int id) {
		  synchronized (tables) {
			   return tables.get(id);
	        }
	}

	

}